﻿<%@ WebHandler Language="VB" Class="Controller" %>

Imports System
Imports System.Web
Imports System.Net
Imports System.IO


Public Class Controller : Implements IHttpHandler
    Private Function RenderControl(ByVal Control As UserControl) As String
        Dim sb As New StringBuilder()
        Dim tw As New StringWriter(sb)
        Dim hw As New HtmlTextWriter(tw)

        Control.RenderControl(hw)
        Return sb.ToString()
    End Function
        
    
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        context.Response.ContentType = "text/html"
          Select Case context.Request.Params("cmd")
            Case "get"
                'Dim pageHolder As Page = New Page()
                Dim UC As Object = New Page().LoadControl("controls/ProductList.ascx")
              
                'Dim ProductList As IProductList = UC
                UC.CategoryId = context.Request.Params("categoryId")
                UC.Bind()
                context.Response.Write(RenderControl(UC))
            
        End Select
        context.Response.End()
        
        
        'context.Response.ContentType = "text/xml"

        'Dim Resp As WebResponse = WebRequest.Create(context.Request.Params("feed")).GetResponse
        'Dim stream As Stream = Resp.GetResponseStream
        'Dim sReader As New StreamReader(stream)
        
        'context.Response.Write(sReader.ReadToEnd)
    End Sub
 
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class